<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>活动系统参数模板列表</title>
    <!--{include file="comm/icheck.tpl"}-->
    <!--引用div做成的下拉框效果样式-->
    <link rel="stylesheet" href="/quanliadmin/docroot/css/department_select.css" type="text/css" media="screen" />
    <!--引用div做成的下拉框效果js-->
    <script language="JavaScript" src="/quanliadmin/docroot/js/department_select.js" type="text/javascript"></script>
</head>
<body>

<style>
    .imageSites{
        position: absolute;
        left:740px;
        top:16px;
    }
    .imageSite{
        position: absolute;
        left:280px;
        top:8px;
    }
</style>

<div class="container">

    
        <div class="comm_content">

            <div class="search-box">
                <div style="position:relative">
                    <form class="form-inline" onsubmit="return false;" id="search_form">
                        <table>
                            <tbody>
                            <tr>
                                <td style="height: 30px;">
                                    <span>config_id：<input type="text" class="form-control input-sm" style="width:148px" value="" name="config_id" id="config_id"></span>
                                </td>
                                <!--td style="height: 30px;">
                                    <span>config_code：<input type="text" class="form-control input-sm" style="width:148px" value="" name="config_code" id="config_code"></span>
                                </td-->
                                <input type="hidden" class="form-control input-sm" style="width:148px" value="systemConfig" name="config_code">
                                <td style="height: 30px;">
                                    <span>config_key：<input type="text" class="form-control input-sm" style="width:148px" value="" name="config_key"></span>
                                </td>
                                <td style="height: 30px;">
                                    <span>config_value：<input type="text" class="form-control input-sm" style="width:148px" value="" name="config_value"></span>
                                </td>

                                <td style="height: 30px;">
                                    <span><input type="button" onclick="config.search();" class="btn btn-primary" value="查询"></span>
                                </td>
                                <td style="height: 30px;">
                                    <span><input type="button" onclick="config.reSet();" class="btn btn-warning" value="重置"></span>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>

            <table id="flex" style="display:none;"></table>

        </div>
    
</div>
<!--HTML OPEN-->
<div style="display:none">
    //区域添加
    <div id="pop" style="display:none">
        <div id="select-content">
            <form id="userForm" class="form-horizontal" role="form" onsubmit="return false;">
                <input type="hidden" id="uuid" name="uuid" value="" />
                <div id="add_user">
                    <div class="form-group">
                        <label for="config_code" class="col-sm-3 control-label"><span style="color:red;">*</span>&nbsp;config_code：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" value="systemConfig" id="config_code" name="config_code" disabled="disabled" placeholder="请输入config_code" style="width: 350px"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="config_key" class="col-sm-3 control-label"><span style="color:red;">*</span>&nbsp;config_key：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" value="" id="config_key" name="config_key" placeholder="请输入config_key" style="width: 350px"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="config_value" class="col-sm-3 control-label"><span style="color:red;">*</span>&nbsp;config_value：</label>
                        <div class="col-sm-9">
                            <textarea class="form-control" id="config_value" name="config_value" style="width: 350px"/></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="config_remark" class="col-sm-3 control-label"><span style="color:red;">*</span>&nbsp;config_remark：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" value="" id="config_remark" name="config_remark" placeholder="请输入config_remark" style="width: 350px"/>
                        </div>
                    </div>

                </div>

            </form>
        </div>
    </div>
</div>

<!--END HTML OPEN-->
<script type="text/javascript">

$(window).ready(function() {

    $("#roleGroupID").on("change", function() {

        var group_id = $(this).val();
        $("#roleID").find("option").show();
        if (group_id > 0) {
            $.each($("#roleID").find("option"), function(k, v) {
                if ($(v).attr("group") != group_id) {
                    $(v).hide();
                }
            });
        }

    });

});

$("#flex").flexigrid({
    url:"/invokingAjax-backend/system/activity.ajax?operFlg=1&config_code=systemConfig",
    dataType: "json",
    colModel : [
        <!--{if $edit_permission}-->
        {display: "操作", width : 120, align: 'center'},
        <!--{/if}-->
        {display: "config_id", width : 120, align: 'center'},
        {display: "config_code", width : 120, align: 'center'},
        {display: "config_key", width : 180, align: 'center'},
        {display: "config_value", width : 180, align: 'center'},
        {display: "config_remark", width : 617, align: 'center'}
    ],
    <!--{if $edit_permission}-->
    buttons : [
        {name: "添加", bclass: "add", onpress : "config.edit"},
        {separator: true},
        {name: "删除", bclass: "delete", onpress : "config.del.check"},
        {separator: true},
        {name: "全选", bclass: "checkAll", onpress : "E.checkAllList"},
        {separator: true},
        {name: "取消全选", bclass: "cancelCheckAll", onpress : "E.cancelCheckAllList"}
    ],
    <!--{/if}-->
    sortname: "config_id",
    sortorder: "desc",
    usepager: true,
    rp: 10,
    useRp: true,
    showTableToggleBtn: true
})

var config = {

    operFlg:"",

    //查询
    search: function() {
        var dt = $('#search_form').serializeArray();
        $("#flex").flexOptions({newp: 1, params: dt}).flexReload();
    },

    //重置
    reSet:function(){
        $('#searchOptions').text('请选择');
        $("#config_id").val('');
        $("#trueName").val('');
        $("#merchantName").val('');
        $("#search_departmentID").val('');
        $("#cityID").val('');
        this.search();

    },

    //清除
    clear: function(){
        $("#roleGroupID").val(0);
        $("#config_id").val("");
        $("#roleID").html(0);
        $("#trueName").val('');
    },

    //编辑
    edit: function(config_id) {
        this.config_id = config_id;
        this.operFlg = 1;
        if(config_id){
            var url = '/invokingAjax-backend/system/activity.ajax?operFlg=2&config_id='+config_id;
        }else{
            var url =  '/invokingAjax-backend/system/activity.ajax?operFlg=2';
        }
        E.loadding.open('正在操作，请稍候...');
        E.ajax_post({
            url: url,
            //data: {},
            call: "config.open"
        });
    },

    open: function(o){

        E.loadding.close();

        var title = "配置修改";

        if(o.code == 404){
            title = "配置添加";
            this.addBox = 'add_user';
        }
        E.popup.open({
            id:"pop",   		 //获取id为"pop"元素内的HTML
            title: title,       //弹出层标题
            css: "width:800px;",     //设置弹出层样式
            btnName: "保存",         //执行“确定”操作的按钮名称
            btnCall:"config.check();"  //点击确定后执行的方法
        });
        $('.square-radio').iCheck({
            checkboxClass: 'icheckbox_square-blue',
            radioClass: 'iradio_square-blue',
            increaseArea: '20%' // optional
        });

        if(config.operFlg == 2){
            $(".nav-tabs li:eq(1)").addClass("active");
            $(".nav-tabs li:eq(1)").siblings().removeClass("active");
            $("#add_user").addClass("hidden");
            $("#add_role").removeClass("hidden");
        }else{
            $(".nav-tabs li:eq(0)").addClass("active");
            $(".nav-tabs li:eq(0)").siblings().removeClass("active");
            $("#add_user").removeClass("hidden");
            $("#add_role").addClass("hidden");
        }

        if(o.code == 200){

            $('#uuid').val(o.data.uuid);
            $('#config_code').val(o.data.config_code);
            $('#config_key').val(o.data.config_key);
            $('#config_value').val(o.data.config_value);
            $('#config_remark').val(o.data.config_remark);

        }

    },

    check: function(){
        this.dt = E.getFormValues("userForm");
        var msg = '';

        if (E.isEmpty(this.dt.config_code)) {
            msg += "config_code不能为空<br>";
        }

        if (E.isEmpty(this.dt.config_key)) {
            msg += "config_key不能为空<br>";
        }

        if (E.isEmpty(this.dt.config_value)) {
            msg += "config_value不能为空<br>";
        }

        if (E.isEmpty(this.dt.config_remark)) {
            msg += "config_remark不能为空<br>";
        }

        if (msg != "") {
            E.alert(msg);
        } else {
            E.confirm("您确认要保存配置信息吗？", "config.save");
        }
    },
    save: function() {

        E.popup.close();

        E.loadding.open("正在保存配置信息，请稍候...");
        E.ajax_post({
            url: "/invokingAjax-backend/system/activity.ajax?operFlg=100&act=edit&config_id="+config_id,
            data: this.dt,
            call: "config.result"
        })
    },
    result: function( o ) {

        if (o.code == 200) {
            E.alert(o.message, 2, "config.load");
        } else {
            E.alert(o.message);
        }
        E.loadding.close();
    },


    load: function(){
        $("#flex").flexReload();
    },

    //角色分配
    role: function( config_id ) {
        this.config_id = config_id;
        this.operFlg = 2;
        var url = '/invokingAjax-backend/system/activity.ajax?operFlg=2&config_id='+config_id;
        E.loadding.open('正在操作，请稍候...');
        E.ajax_post({
            url: url,
            //data: {},
            call: "config.open"
        });
    },

    change: {

        config_id: "",
        useFlg: "",

        test:function(){
            alert()
        },

        confirm: function(config_id, useFlg) {
            this.config_id = config_id;
            this.useFlg = useFlg;
            if (useFlg == 0) {
                E.confirm("您确认要禁用该配置吗？", "config.change.execute");
            } else {
                E.confirm("您确认要启用该配置吗？", "config.change.execute");
            }
        },

        execute: function() {
            if (this.useFlg == 0) {
                E.loadding.open("正在禁用配置，请稍候...");
            } else {
                E.loadding.open("正在启用配置，请稍候...");
            }
            E.ajax_post({
                url: "/invokingAjax-backend/system/activity.ajax?operFlg=100&act=change",
                data: {
                    config_id: this.config_id,
                    useFlg: this.useFlg
                },
                call: "config.change.result"
            });
        },

        result: function( o ) {
            E.loadding.close();
            if (o.code == 200) {
                config.load();
                E.alert(o.message, 2);
            } else {
                E.alert(o.message);
            }
        }

    },

    del: {

        u_array: "",

        check: function() {

            //获取选中的行的行数
            if ($('.trSelected',flex).length == 0) {

                E.alert('请选择要删除的配置');

            } else {

                this.u_array = new Array();

                $.each($('.trSelected',flex), function(k, v) {
                    config.del.u_array.push($(v).attr("id").substr(3));
                });

                //弹出确认层
                E.confirm("您确认要删除吗？", "config.del.execute");

            }

        },

        execute: function() {

            E.loadding.open("正在删除配置，请稍候...");
            E.ajax_post({
                url: "/invokingAjax-backend/system/activity.ajax?operFlg=100&act=del",
                data: {
                    ids: this.u_array
                },
                call: "config.del.result"
            });

        },

        result: function( o ) {
            E.loadding.close();
            if (o.code == 200) {
                config.load();
                E.alert(o.message, 2);
            } else {
                E.alert(o.message);
            }
        }

    },
    changed: function(ythis,boxID){

        this.addBox = boxID;

        $(ythis).addClass('active').siblings().removeClass('active');

        $('#'+boxID.toString()).removeClass('hidden').siblings().addClass('hidden');

    }

};

$(window).ready(function() {

    $(document).on('ifChecked', 'input[name=cityID]', function() {

        var cityID = $(this).attr('id').replace('city-checkbox-', '');

        E.ajax_get({
            url: '/invokingAjax-comm/bill/distribution.ajax?operFlg=4',
            data: {
                deliver_cityid: cityID
            },
            call: function( obj ) {

                if(obj.code ==200 && obj.data != null){

                    var distributionHtml = '<div id="distribution_box_' + cityID + '">';

                    $.each(obj.data, function(i,val){
                        distributionHtml +='<div class="fl" style="margin: 0px 10px 10px 0px;">';

                        if (E.inArray(val.distribution_id, config.distribution)) {
                            distributionHtml +='<input type="checkbox" class="square-radio" id="distribution-checkbox-'+val.distribution_id+'" name="distributionID" value="'+val.distribution_id+'" checked>';
                        } else {
                            distributionHtml +='<input type="checkbox" class="square-radio" id="distribution-checkbox-'+val.distribution_id+'" name="distributionID" value="'+val.distribution_id+'">';
                        }

                        distributionHtml +='<label for="distribution-checkbox-'+val.distribution_id+'" style="margin-left: 10px;">'+val.distribution_name+'</label>';
                        distributionHtml +='</div>';
                    });

                    distributionHtml += '</div>';

                    $('#distribution').append(distributionHtml);

                    $('.square-radio').iCheck({
                        checkboxClass: 'icheckbox_square-blue',
                        radioClass: 'iradio_square-blue',
                        increaseArea: '20%' // optional
                    });
                }
            }
        });
    });

    $(document).on('ifUnchecked', 'input[name=cityID]', function() {
        var cityID = $(this).attr('id').replace('city-checkbox-', '');
        $('#distribution_box_' + cityID).remove();
    });
});
</script>
</body>
</html>